{% extends 'notebooks/authentication/base.html' %}
{% block css %}
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
        }

        body {
            height: 100%;
        }

        .div_container {
            height: 100%;
            background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
        }

        .login-wrapper {
            background-color: #fff;
            width: 388px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }

        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128, 125, 125);
            font-size: 15px;
            outline: none;
        }


        .input-item::placeholder {
            text-transform: uppercase;
        }

        .btn {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
            color: #fff;
        }

        .msg {
            text-align: center;
            line-height: 88px;
        }

        a {
            text-decoration-line: none;
            color: #abc1ee;
        }
    </style>
{% endblock %}

{% block content %}

    <div class="div_container">
        <div class="login-wrapper">
            <div ><a class="btn-primary btn-xs" href="{% url 'home' %}">home</a></div>

            <div class="header">Login</div>
            <div class="form-wrapper">
                {% csrf_token %}
                <input type="text" name="username" id="id_username" placeholder="username" class="input-item">
                <input type="password" name="password" id="id_password" placeholder="password" class="input-item">

                <div class="btn" id="put">Login</div>
            </div>
            <div class="msg">
                你没有登录？
                <a href="{% url 'notebook:register' %}">注册</a>
            </div>
        </div>
    </div>

{% endblock %}


{% block js %}
    <script>
        $("#put").click(function () {
            var username = $("#id_username").val()
            var password = $("#id_password").val()

            $.ajax({
                url: "",
                type: "post",
                dataType: "json",
                data: {
                    "username": username,
                    "password": password,
                    "csrfmiddlewaretoken": "{{ csrf_token }}",
                },
                success: function (args) {
                    if (args.code === 200) {
                        window.location.href = "{% url 'home' %}"
                    } else {
                        alert(args.msg)
                    }
                }
            })


        })


    </script>
{% endblock %}